﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Less;
using Less.Core;
using Less.Core.Loggers;


namespace LessBoard
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            Initializer();
            Log.Warning("Application Started");

            
        }

        public void Initializer()
        {
            try
            {
                Status.LoadStatus();
                Config.CanUseDatabase = true;
                Log.Loggers.Add(new DatabaseLogger());
            }
            catch (Exception e)
            {
                Log.Fatal(e, EntryCategories.Core);
            }
        }
   
        
    }
}